mydata <- read.csv2("Energy.csv")
head(mydata)
## Size Consumption HeatingType
## 1 130 2954.896 Gas
## 2 80 2198.613 Gas
## 3 100 2682.367 Gas
## 4 40 1808.698 Gas
## 5 155 3037.554 Gas
## 6 80 2550.555 Gas
Description of variables:
mydata$HeatingType <- factor(mydata$HeatingType,
levels = c("Gas", "Electricity"),
labels = c("Gas", "Electricity"))
library(car)
## Loading required package: carData
scatterplot(Consumption ~ Size | HeatingType,
ylab = "Consumption of energy in kWh",
xlab = "Size of an apartment in m2",
smooth = FALSE,
boxplots = FALSE,
data = mydata)
fit <- lm(Consumption ~ Size + HeatingType + Size:HeatingType,
data = mydata)
summary(fit)
##
## Call:
## lm(formula = Consumption ~ Size + HeatingType + Size:HeatingType,
## data = mydata)
##
## Residuals:
## Min 1Q Median 3Q Max
## -708.05 -96.61 -4.28 88.68 649.28
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1264.295 148.923 8.490 4.07e-10 ***
## Size 12.562 1.415 8.878 1.35e-10 ***
## HeatingTypeElectricity 964.379 209.522 4.603 5.02e-05 ***
## Size:HeatingTypeElectricity 12.265 2.178 5.632 2.16e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 235.5 on 36 degrees of freedom
## Multiple R-squared: 0.9608, Adjusted R-squared: 0.9576
## F-statistic: 294.3 on 3 and 36 DF, p-value: < 2.2e-16